package com.shigen.file.service.impl;

import com.shigen.file.entity.Visitors;
import com.shigen.file.mapper.VisitorsMapper;
import com.shigen.file.service.IVisitorsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shigen.file.util.IPUtil;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 访客记录表 服务实现类
 * </p>
 *
 * @author shigen.fu
 * @since 2022-06-04
 */
@Service
public class VisitorsServiceImpl extends ServiceImpl<VisitorsMapper, Visitors> implements IVisitorsService {

  @Override
  public int addVisitor(Visitors visitors, HttpServletRequest request) {
    String ip = IPUtil.getIp(request);
    String cityInfoStr = IPUtil.getCityInfoStr(ip);

    visitors.setCreateTime(new Date())
        .setIp(ip)
        .setPosition(cityInfoStr)
        .setIsDel(0);
    return getBaseMapper().insert(visitors);
  }
}
